package com.mti;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CityWeatherAdapter extends BaseAdapter{
	List<CityWeather> listFavorites;
	LayoutInflater inflater;

	public CityWeatherAdapter(Context context,List<CityWeather> listFavParam) {
		inflater = LayoutInflater.from(context);
		this.listFavorites = listFavParam;
	}

	public int getCount() {
		return listFavorites.size();
	}

	public Object getItem(int position) {
		return listFavorites.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	// Buffer
	private class ViewHolder {
		TextView temp_row;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.favorite_row, null);
			holder.temp_row  = (TextView) convertView.findViewById(R.id.temp_row);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		if (GiveMeWeatherActivity.gIsFahrenheit) {
			holder.temp_row.setText(listFavorites.get(position).getTempF());
		}
		else {
			holder.temp_row.setText(listFavorites.get(position).getTempC());
		}	
		return convertView;
	}
}
